cmake_minimum_required(VERSION 3.10.0)
project(learn_sdl3 VERSION 0.1.0 LANGUAGES C CXX)

cmake_policy(SET CMP0074 NEW)

#设置多核并行编译
set(CMAKE_BUILD_PARALLEL_LEVEL  4)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CAMKE_CXX_STANDARD_REQUIRED True)

# 设置编译选项
if (MSVC)
    add_compile_options(/W4)
else()
    add_compile_options(-mwindows -Wall -Wextra -Wpedantic)
endif()

set(TARGET ${PROJECT_NAME}-${CMAKE_SYSTEM_NAME})

# 设置编译输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR})

# 查找并载入 cmake 预设
find_package(SDL3 REQUIRED)
find_package(SDL3_image REQUIRED)
find_package(SDL3_ttf REQUIRED)
find_package(SDL3_mixer REQUIRED)
find_package(glm REQUIRED)

link_libraries(SDL3::SDL3)
link_libraries(SDL3_image::SDL3_image)
link_libraries(SDL3_ttf::SDL3_ttf)
link_libraries(SDL3_mixer::SDL3_mixer)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    target_link_libraries(${TARGET} SDL3)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
    # target_link_libraries(${TARGET} mingw32)
    # target_link_libraries(${TARGET} SDL3)
    # target_link_options(${TARGET} PRIVATE -mwindows)
endif()

include_directories(src
                    src/core
                    ${SDL3_INCLUDE_DIR}
                    ${SDL3_IMAGE_INCLUDE_DIR}
                    ${SDL3_TTF_INCLUDE_DIR}
                    ${SDL3_MIXER_INCLUDE_DIR})


# 设置通用源文件
set(SOURCES
    src/core/game.cpp
    src/core/object.cpp
    src/core/actor.cpp
    src/core/scene.cpp
    src/core/asset_store.cpp
    src/core/object_world.cpp
    src/core/object_affiliate.cpp
    src/affiliate/sprite.cpp
    src/affiliate/sprite_anim.cpp
    src/affiliate/collider.cpp
    src/affiliate/affiliate_bar.cpp
    src/world/effect.cpp
    src/world/spell.cpp
    src/raw/stats.cpp
    src/raw/timer.cpp
    src/raw/weapon.cpp
    src/screen/ui_mouse.cpp
    src/main.cpp
    src/player.cpp
    src/enemy.cpp
    src/spawner.cpp
    src/scene_main.cpp
    src/weapon_thunder.cpp
)

# 根据平台向"通用源文件"追加平台专属的文件
if(WIN32)
    # 如果是 Windows 平台，将资源文件追加到源文件列表
    list(APPEND SOURCES resources.rc)
endif()
# TODO: MacOs 和 Linux 平台

# 添加可执行文件，使用配置好的 "SOURCES" 变量
add_executable(${TARGET} WIN32 ${SOURCES})

# 链接库
target_link_libraries(${TARGET}
                        ${SDL_LIBRARIES}
                        SDL3_image::SDL3_image
                        SDL3_mixer::SDL3_mixer
                        SDL3_ttf::SDL3_ttf
                        glm::glm
)

# 不要弹出控制台窗口
if (MSVC)
    target_link_options(${TARGET} PRIVATE "/SUBSYSTEM:WINDOWS")
endif()


# add_executable()

